export class CommonFunction {

    // x(): write a number in hexadecimal
    // @param n: the number
    // @param i (optional): the length of the hexadecimal value, with leading zeros (max: 8)
    x(n, i) { return ((i ? 1e7 : "") + n.toString(16).toUpperCase()).slice(-i); }
    /********** Binary tools **********/
    // lshift()
    // @params a, b
    // @return a << b
    lshift(number, shift) { return number * Math.pow(2, shift); }
    // rshift()
    // @params a, b
    // @return a >> b
    rshift(number, shift) { return Math.floor(number / Math.pow(2, shift)); }
    // b()
    // @params number, start, end
    // @return a number representing the bits of number read from start to end
    // end param is optional. By default, one bit is read.
    b(number, start, end) { return rshift(number, start) & (Math.pow(2, (end || start) - start + 1) - 1); }
    // ror()
    // @params number, length, bits
    // @return the number (which is "length" bits long) after a right rotation (make the "bits" first bits of the number, last) 
    ror(number, length, bits) { return lshift((number & Math.pow(2, bits) - 1), length - bits) + rshift(number, bits); }


}

